package com.ruoyi.system.controller;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.domain.Platforms;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.service.IPlatformsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 第三方平台表，记录对接的外部平台信息 前端控制器
 * </p>
 *
 * @author jiabao
 * @since 2025-06-26
 */
@RestController
@RequestMapping("/platforms")
public class PlatformsController extends BaseController {
    @Resource
    private IPlatformsService PlatformsService;

    /**
     * 查询第三方平台，记录对接的外部平台信息列表
     */
    @RequiresPermissions("system:platforms:list")
    @GetMapping("/list")
    public TableDataInfo list(Platforms Platforms)
    {
        startPage();
        List<Platforms> list = PlatformsService.selectPlatformsList(Platforms);
        return getDataTable(list);
    }

    /**
     * 导出第三方平台，记录对接的外部平台信息列表
     */
    @RequiresPermissions("system:platforms:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Platforms Platforms)
    {
        List<Platforms> list = PlatformsService.selectPlatformsList(Platforms);
        ExcelUtil<Platforms> util = new ExcelUtil<Platforms>(Platforms.class);
        util.exportExcel(response, list, "第三方平台，记录对接的外部平台信息数据");
    }

    /**
     * 获取第三方平台，记录对接的外部平台信息详细信息
     */
    @RequiresPermissions("system:platforms:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(PlatformsService.selectPlatformsById(id));
    }

    /**
     * 新增第三方平台，记录对接的外部平台信息
     */
    @RequiresPermissions("system:platforms:add")
    @PostMapping
    public AjaxResult add(@RequestBody Platforms Platforms)
    {
        return toAjax(PlatformsService.insertPlatforms(Platforms));
    }

    /**
     * 修改第三方平台，记录对接的外部平台信息
     */
    @RequiresPermissions("system:platforms:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody Platforms Platforms)
    {
        return toAjax(PlatformsService.updatePlatforms(Platforms));
    }

    /**
     * 删除第三方平台，记录对接的外部平台信息
     */
    @RequiresPermissions("system:platforms:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(PlatformsService.deletePlatformsByIds(ids));
    }
}
